package cn.iocoder.yudao.module.robot.service.callrecordbills;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.robot.controller.admin.callrecordbills.vo.*;
import cn.iocoder.yudao.module.robot.dal.dataobject.callrecordbills.CallRecordBillsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.robot.dal.mysql.callrecordbills.CallRecordBillsMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 机器人通话详情 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class CallRecordBillsServiceImpl implements CallRecordBillsService {

    @Resource
    private CallRecordBillsMapper callRecordBillsMapper;

    @Override
    public Long createCallRecordBills(CallRecordBillsSaveReqVO createReqVO) {
        // 插入
        CallRecordBillsDO callRecordBills = BeanUtils.toBean(createReqVO, CallRecordBillsDO.class);
        callRecordBillsMapper.insert(callRecordBills);
        // 返回
        return callRecordBills.getId();
    }

    @Override
    public void updateCallRecordBills(CallRecordBillsSaveReqVO updateReqVO) {
        // 校验存在
//        validateCallRecordBillsExists(updateReqVO.getId());
        // 更新
        CallRecordBillsDO updateObj = BeanUtils.toBean(updateReqVO, CallRecordBillsDO.class);
        callRecordBillsMapper.updateById(updateObj);
    }

    @Override
    public void deleteCallRecordBills(Long id) {
        // 校验存在
//        validateCallRecordBillsExists(id);
        // 删除
        callRecordBillsMapper.deleteById(id);
    }

//    private void validateCallRecordBillsExists(Long id) {
//        if (callRecordBillsMapper.selectById(id) == null) {
//            throw exception(CALL_RECORD_BILLS_NOT_EXISTS);
//        }
//    }

    @Override
    public CallRecordBillsDO getCallRecordBills(Long id) {
        return callRecordBillsMapper.selectById(id);
    }

    @Override
    public PageResult<CallRecordBillsDO> getCallRecordBillsPage(CallRecordBillsPageReqVO pageReqVO) {
        return callRecordBillsMapper.selectPage(pageReqVO);
    }

}